Week 11

As a team we decided we wanted to make speech controlled chess. This was decided based on two main points. First one is, it is really cool idea. The second one, the work can be split up between all people in the team.

The main thing that needs to be done, to succesfully complete the project is to split the job and make sure everyone is doing their part. We started by creating google doc to split the work to individual task and then everyone chose what they wanted to do. Also to specify before hand, how will the individual components warks between each other. We agreed on using objects with predefined functions.

Now I will focus on my part in the project. My job was to create the GUI app, that would incorporate all the functionality created by other people in the team. I also had to code the chess logic to check for valid moves and to generate all valid moves.

For the GUI app I chose python graphics library pygame. For the chess logic i used python package chess, but i had to code some functionality for the visualization. Here is first look at the app working without chess logic:

The code, as of now, consists of about 600 lines of code in the "main.py" and about 2000-2500 lines of code in total. So i won't post it here, but here is the link to our github. The project, as of writing this documentation, is still being upgraded.
Back to the app, as you can see, there was no checking of correct moves so i coded the chess logic. Here is how it looked with chess logic:

Now the app shows you valid moves for the piece, taking into account checks, castling and also pawn promotion.
Next it was time to incorporote work of other people in our team. I started by incorporating the ability to play vs stockfish. I also added menu for selecting what mode you want to play. Here is showcase of two AIs playing vs each other:

Than i incorporated the voice controll. It worked great, but unfortunately it somehow broke in the process of adding other things and will need more work.
Now it was time to interporate recalculating the played moves, to coords for the motor. It needed to take into account other figures to not crash into them. It somehow worked, but not consistently. So i coded A star algorithm for path finding and avoiding figures. I also implemented merging of the coords, so that least amount of commands had to be sent.

On the left you can see optimal path from the red square to the green square (with avoiding figures), but not with optimal amount of commands. Each blue, red and green rectangle is a command that needs to be send, eventhough the motors can go in a staright line. On the right is optimized path with optimized amount of commands. Here is the code, how i optimized the commands:

                
def group_path(self, path):
    """
    :param path: list [(x1, y1), (x2, y2) ... ] 
    :return:  list [(x1, y1)... ] but optimized 
    """
    new_path = []
    prev_dx, prev_dy = 0, 0
    for i in range(len(path) - 1):
        dx, dy = path[i][0] - path[i + 1][0], path[i][1] - path[i + 1][1]
        if dx == prev_dx and dy == prev_dy:
            continue
        else:
            new_path.append(path[i])
            prev_dx = dx
            prev_dy = dy
    new_path.append(path[-1])
    return new_path
                
            

The path-finding was needed, because we needed to drive from anywhere to the right center of the board, to automatically throw away captured pieces from the board, and not hit any other pieces.
Last thing was to incorporate the serial communication for sending the commands to Arduino UNO.

A lot of other details needed to be done, but if i were to write about all of them, this page would be reaaaally long. But it was for example: detecting special move like castling, sending moves for castling, implementing AI vs AI, reseting board ...

Anyways here is our first try after connecting hardware and software. This is version without capture still.

After adding the hardware and software for capturing pieces, here is how it looked (AI vs AI, without optimal commands):

After fixing some software bugs, improving hardware (cushion to prevent vibrations - for the pieces to not move when they are not supposed to) this was the final version. In the video you can see both sides castling. Also this is already with the A* implemented and moves take to least amount of stops possible.

←Back